package com.jy.unkown;

import android.app.Activity;
import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.webkit.DownloadListener;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.TextView;

import com.amjy.dsl.R;
import com.jy.common.base.BaseActivity;
import com.jy.unkown.view.CusWebViewClient;
import com.jy.utils.utils.StatusBars;

public class WebActivty extends BaseActivity {
    private WebView webview;
    private View backView;
    private View closeView;
    private TextView titleTv;

    public static void jump(Activity activity, String url) {
        Intent intent = new Intent(activity, WebActivty.class);
        intent.putExtra("url", url);
        activity.startActivity(intent);
    }


    @Override
    public void initData() {

    }

    @Override
    public void initUI() {
        StatusBars.setStatusBarTextColor(this,true);
        webview = findViewById(R.id.webview);
        backView = findViewById(R.id.backView);
        titleTv = findViewById(R.id.titleTv);
        closeView = findViewById(R.id.close);
        webview.setWebViewClient(new CusWebViewClient());
        closeView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        backView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (webview.canGoBack()) {
                    closeView.setVisibility(View.VISIBLE);
                    webview.goBack();
                    return;
                }
                finish();
            }
        });

        try {
            WebSettings webSettings = webview.getSettings();
            webSettings.setBuiltInZoomControls(true);
            webSettings.setSupportZoom(true);
            webSettings.setJavaScriptEnabled(true);
        } catch (Exception e) {
        }
        webview.setDownloadListener(new DownloadListener() {
            @Override
            public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
                String key = getIntent().getStringExtra("key");
                if (!TextUtils.isEmpty(key)) {
                    UNKOWN.notifyDownload(key, url);
                }
            }
        });
        webview.loadUrl(getIntent().getStringExtra("url"));
        StatusBars.setStatusBarTextColor(this, false);

    }

    @Override
    public int layoutId() {
        return R.layout.activity_web_xx2;
    }

    @Override
    protected void onStop() {
        super.onStop();
        isStop = true;
    }

    @Override
    protected void onPause() {
        super.onPause();
        try {
            webview.onPause();
        } catch (Exception e) {
        }
        isStop = true;
        super.onPause();
    }


    @Override
    protected void onResume() {
        super.onResume();
        try {
            webview.onResume();
        } catch (Exception e) {
        }
        super.onResume();
        lastTime = System.currentTimeMillis();
        isStop = false;
    }

    boolean isStop = false;
    long lastTime = 0L;


}
